#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace PdfCreative.Pdf.Graphics
{
    /// <summary>
    /// The StyledText class represents fully styled text. Text can be expressed in a number of styles, encapsulated
    /// by InlineText instances. The StyledText class represents the whole of the text. It is used by the
    /// Graphics class to draw fully styled text.
    /// </summary>
    public class StyledText
    {
        // Private fields
        // ==============
        #region Private fields
        private List<InlineText> _inlines;          // The inline text elements.
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Retrieves the inline text elements of this styled text instance.
        /// </summary>
        public IEnumerable<InlineText> Inlines
        {
            get { return _inlines; }
        }
        #endregion



        // Public methods
        // ==============
        #region Public methods
        /// <summary>
        /// Appends inline text element to the text in this instance.
        /// </summary>
        /// <param name="inline">The inline text.</param>
        /// <returns>A reference to this instance.</returns>
        /// <exception cref="ArgumentNullException">The inline text, or one of its properties, is a Null reference.</exception>
        public StyledText Append(InlineText inline)
        {
            if(null==inline) throw new ArgumentNullException("inline");
            if (null == inline.Brush) throw new ArgumentNullException("inline.Brush");
            if (null == inline.Font) throw new ArgumentNullException("inline.Font");
            if (null == inline.Text) throw new ArgumentNullException("inline.Text");

            _inlines.Add(inline);
            return this;
        }

        /// <summary>
        /// Appends the text with the specified brush and font.
        /// Note that the font size is expressed in points, regardless of the page unit of the Graphics
        /// instance that the text will be drawn on.
        /// </summary>
        /// <param name="text">The text to add.</param>
        /// <param name="brush">The brush to draw the text in.</param>
        /// <param name="font">The font to use.</param>
        /// <param name="fontSize">The size of the font, in points.</param>
        /// <returns>A reference to this instance.</returns>
        /// <exception cref="ArgumentNullException">The text, brush or font is a Null reference.</exception>
        public StyledText Append(string text, Brush brush, Font font, float fontSize)
        {
            return this.Append(
                new InlineText(text, brush, font, fontSize));
        }
        #endregion



        // Public constructor
        // ==================
        #region Public constructor
        /// <summary>
        /// Constructs a new StyledText instance.
        /// </summary>
        public StyledText()
        {
            _inlines = new List<InlineText>();
        }

        /// <summary>
        /// Constructs a new StyledText instance with the specified text and style.
        /// Note that the font size is expressed in points, regardless of the page unit of the Graphics
        /// instance that the text will be drawn on.
        /// </summary>
        /// <param name="text">The text to add</param>
        /// <param name="brush">The brush to draw the text in.</param>
        /// <param name="font">The font to use.</param>
        /// <param name="fontSize">The size of the font, in points.</param>
        /// <exception cref="ArgumentNullException">The text, brush or font is a Null reference.</exception>
        public StyledText(string text, Brush brush, Font font, float fontSize)
            : this()
        {
            this.Append(text, brush, font, fontSize);
        }

        /// <summary>
        /// Constructs a new StyledText instance with the specified inline text.
        /// </summary>
        /// <param name="inline">The inline text to start this instance with.</param>
        /// <exception cref="ArgumentNullException">The inline text, or one of its properties, is a Null reference.</exception>
        public StyledText(InlineText inline)
            : this()
        {
            this.Append(inline);
        }

        /// <summary>
        /// Constructs a new StyledText instance with the specified inline texts.
        /// </summary>
        /// <param name="inlines">A list of inline text elements to start this instance with.</param>
        /// <exception cref="ArgumentNullException">The list, or one of its elements, is a Null reference.</exception>
        public StyledText(IEnumerable<InlineText> inlines) : this()
        {
            if (null == inlines)
                throw new ArgumentNullException("inlines");

            foreach (InlineText inline in inlines) this.Append(inline);
        }
        #endregion

    } // StyledText class
}
